using Aurora.Security.MD5;
using Gateway.Common.Entity;

namespace Gateway.Domain.Entities;

/// <summary>
/// 用户列表
/// </summary>
public class User : AggregateRootEntityBase
{
    /// <summary>
    /// 用户头像
    /// </summary>
    public string UserAvatar { get; private set; }

    /// <summary>
    /// 姓名
    /// </summary>
    public string UserName { get;private set; }

    /// <summary>
    /// 账号
    /// </summary>
    public string Account { get;private set; }

    /// <summary>
    /// 编号
    /// </summary>
    public string UserNo { get;private set; }

    /// <summary>
    /// 所属角色标识
    /// </summary>
    public List<string> RoleIds { get;private set; }

    /// <summary>
    /// 部门标识
    /// </summary>
    public string DepartmentId { get;private set; }

    /// <summary>
    /// 密码
    /// </summary>
    public string Password { get;private set; }

    public User()
    {
    }

    /// <summary>
    /// 构造函数
    /// </summary>
    /// <param name="userName">用户名称</param>
    /// <param name="userAvatar">用户头像</param>
    /// <param name="departmentId">部门标识</param>
    /// <param name="password">密码</param>
    /// <param name="roleIds">角色id集合</param>
    /// <param name="account">账号</param>
    public User(
        string userName = default,
        string userAvatar = default,
        string departmentId = default,
        string password = default,
        List<string> roleIds = default,
        string account = default)
    {
        this.UserNo = "USER"+DateTime.Now.ToString("yyyyMMddHHmmss")+new Random().Next(1000) ;
        this.UserName = userName;
        this.UserAvatar = userAvatar;
        this.Account = account;
        this.DepartmentId = departmentId;
        this.RoleIds = roleIds;
        if (!string.IsNullOrEmpty(password))
        {
            this.Password = password.ToMD5String();
        }
    }

    public void Update(string userName = default,
        string userAvatar = default,
        string departmentId = default,
        List<string> roleIds = default,
        string account = default)
    {
        this.UserName = userName;
        this.UserAvatar = userAvatar;
        this.Account = account;
        this.DepartmentId = departmentId;
        this.RoleIds = roleIds;
    }

    /// <summary>
    /// 修改密码
    /// </summary>
    /// <param name="password"></param>
    public void ChangePassword(string password)
    {
        this.Password = password.ToMD5String();
    }
    
    /// <summary>
    /// 修改姓名
    /// </summary>
    /// <param name="userName"></param>
    public void ChangeName(string userName)
    {
        this.UserName = userName;
    }
}